package com.yulongtian.interviewWorks.day20220825;

/**
 * https://leetcode.cn/problems/intersection-of-two-linked-lists-lcci/
 *
 * @author YulongTian
 * @date 2022/8/25 - 14:17
 */
public class Test02 {
    public static void main(String[] args) {

    }

    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode p1=headA;
        ListNode p2=headB;

        while (p1!=null){
            p2=headB;
            while (p2!=null){
                if(p1==p2){
                    return p1;
                }
                p2=p2.next;
            }
            p1=p1.next;
        }
        return null;
    }

    public class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
            next = null;
        }
    }


}
